const express = require('express');
const router = express.Router();
const service = require('../service/userTelService');
const path = "/userTel";
//service.queryById(1);
router.get('/hello', function (req, res) {
    res.send('Hello World');
})

// router.get('/queryAll', function (req, res) {
//     //let data=service.queryAll();
//     service.queryAll().then((data) => {
//         res.json(data)
//     })
//     //let data={success:true};

// })
router.get('/queryAll', async (req, res) => {
    let data = await service.queryAll()
    res.json(data)
})
router.get('/queryCount', async (req, res) => {
    let data = await service.queryCount()
    res.json(data)
})


router.get('/listPage', async (req, res) => {
    let pageSize = parseInt(req.query.pageSize);
    let currentPageNo = parseInt(req.query.currentPageNo);
    let offset = (currentPageNo - 1) * pageSize;
    //查分页
    let data = await service.listPage(offset, pageSize);
    const result = {success:true, message:'查询成功', data:data, countNum:data[0].countNum};
    //返回数据{success:true, message:success, data:[...], count:100}
    // const result = {};
    res.json(result)

})


module.exports = (app) => {
    //注册路由
    app.use(path, router)
    //demoRouter(app)
}

